import { Component } from '@angular/core';

import { HTTP } from '@ionic-native/http';

import { AboutPage } from '../about/about';
import { ContactPage } from '../contact/contact';
import { HomePage } from '../home/home';
import { DhzqPage } from '../dhzq/dhzq';

import { IndexPage } from '../index/index';
import { ThemeableBrowser, ThemeableBrowserOptions, ThemeableBrowserObject } from '@ionic-native/themeable-browser';
import { Events,AlertController  } from 'ionic-angular';
@Component({
  templateUrl: 'tabs.html'
})
export class TabsPage {

  tab1Root = HomePage;
  tab2Root = DhzqPage;
  tab3Root = ContactPage;
  tab4Root = AboutPage;
  tabHomeClickEvent: any; 
 userid=localStorage.getItem("userid");
   
    
    username=localStorage.getItem("username");
    userpassword=localStorage.getItem("userpassword");

  constructor(public http:HTTP,private themeableBrowser: ThemeableBrowser,public events: Events,private malert:AlertController) {
    // this.tabHomeClickEvent = function(e) {
    //   //首页处于活动状态
    //   if(2 == this.selectedIndex){
    //     this.dui();
    //   }
    // }
  }


  load(){
    // alert(1); 
    this.username=localStorage.getItem("username");
    this.userpassword=localStorage.getItem("userpassword");
    let logisurl:string ="http://118.31.79.20:8080/Stock/login/login.do?username="+ this.username+'&&password='+ this.userpassword; 
         // 个人信息请求
            this.http.get(logisurl, {}, {})
             .then(data => {
                //获取的数据
                var datass=JSON.parse(data.data);
                IndexPage.userid=datass.data.uid; //用户id
                IndexPage.username = datass.data.username; //用户名
                IndexPage.usermoney = datass.data.money; //用户牛牛币
                //数据改变
                // alert(IndexPage.userid);
            })
            .catch(error => {
                 this.mWinds("网络异常");           
                 
               
            });
  }

  dui(){
    //   var pass="http://118.31.79.20/?/mobile/ajax/applogin/?username="+IndexPage.usename+"&password="+IndexPage.usepassword+"&url= {\"url\":\"mobile/init\"}";
    //   +  IndexPage.usename + IndexPage.usepassword;
    this.username=localStorage.getItem("username");
    this.userpassword=localStorage.getItem("userpassword");
      if(this.userid==''||this.userid==null){
          var pass="http://118.31.79.20"
        }else{
          var pass="http://118.31.79.20/?/mobile/ajax/applogin/?a="+this.username+"&b="+this.userpassword;
        }
  
    const options: ThemeableBrowserOptions = {
     statusbar: {
        
         color: '#000'
     },
     toolbar: {
         height: 40,
         color: '#000'
     },
     title: {
         color: '#FFFFFF', 
         staticText:"0元夺宝",
         showPageTitle: true,
        
     },
    // backButton: {
    //      image: 'ic_action_previous_item',
    //      imagePressed: 'back_pressed',
    //      align: 'left',
        
    //  },
    //  forwardButton: {
    //      image: 'ic_action_next_item',
    //      imagePressed: 'forward_pressed',
    //      align: 'left',
    //      event: 'forwardPressed'
    //  },
     closeButton: {
         image: 'ic_action_guan',
         imagePressed: 'ic_action_guan',
         align: 'left',
         event: 'closePressed'
     },
            backButtonCanClose: true,
            // clearcache:true,
            // clearsessioncache:true
           
        };
        const browser: ThemeableBrowserObject = this.themeableBrowser.create(pass, '_blank', options);
         browser.on("closePressed").subscribe((data) => {  
                //   alert("zhangxun");
                
            let logisurl:string ="http://118.31.79.20/?/mobile/ajax/outAppLogin"; 
         // 个人信息请求
            this.http.get(logisurl, {}, {})
             .then(data => {
                //获取的数据
                console.log(data.data);
                var datass=JSON.parse(data.data);
                // this.huabi.money = datass.data.money; //用户牛牛币
                //数据改变
                // alert('用户id'+ datass.id)
                // alert('用户方法'+datass.username);
                // alert(datass.pwd);
                // localStorage.setItem("userid",'8704');
                // localStorage.setItem("username",'15038278261');
                // localStorage.setItem("userpassword",'yishengyishi');
                
                console.log(data)
                // alert(IndexPage.userid);
            })
            .catch(error => {
                // var msg= "网络连接错误"
                //  this.mWind(msg);     
            });
                }, (err) => {  
                    alert('share:error'); 
                    console.error('onError');  });
    }

     /**
     * 无按钮
     * @param msg 
     */
    mWinds(msg){
        let alert= this.malert.create({
      title :"提示",
      message:msg,     
    });
  alert.present();

    }

}
